<?php
$from = $_POST['from'];
$to = $_POST['to'];
$carrier = $_POST['carrier'];
$message = stripslashes($_POST['message']);

$mysql_host = "mysql16.000webhost.com";
$mysql_database = "a1863493_venture";
$mysql_user = "a1863493_teamven";
$mysql_password = "teamventure1";

$link = mysql_connect($mysql_host, $mysql_user, $mysql_password);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_select_db($mysql_database, $link) or die ("<p> Fail </p>");

if ((empty($from)) || (empty($to)) || (empty($message))) {
header ("Location: sms_error.php");
}

else if ($carrier == "verizon") {
$formatted_number = $to."@vtext.com";
mail("$formatted_number", "SMS", "$message"); 
// Currently, the subject is set to "SMS". Feel free to change this.

$query = sprintf("INSERT INTO cust_acct(idcust_acct,name, pass, email, phone) VALUES(1,'Bob', 'pass', 'bob@bob.bobnet', '123')");
$message = "Success";
$result = mysql_query($query);
if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
}
echo $message;
header ("Location: sms_success.php");
}

else if ($carrier == "tmobile") {
$formatted_number = $to."@tomomail.net";
mail("$formatted_number", "SMS", "$message");

header ("Location: sms_success.php");
}

else if ($carrier == "sprint") {
$formatted_number = $to."@messaging.sprintpcs.com";
mail("$formatted_number", "SMS", "$message");

header ("Location: sms_success.php");
}

else if ($carrier == "att") {
$formatted_number = $to."@txt.att.net";
mail("$formatted_number", "SMS", "$message");
header ("Location: sms_success.php");
}

else if ($carrier == "virgin") {
$formatted_number = $to."@vmobl.com";
mail("$formatted_number", "SMS", "$message");

header ("Location: sms_success.php");
}

mysql_close($link);
?>